package com.api.dao;

import cn.hserver.plugin.mybatis.annotation.Mybatis;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.api.domain.entity.UserEntity;
import com.api.domain.vo.UserVO;

import java.util.List;

/**
 * @author hxm
 */
@Mybatis
public interface UserDao extends BaseMapper<UserEntity> {


    default UserEntity findUserByUsername(String username) {
        List<UserEntity> select = selectList(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUsername, username));
        if (select.isEmpty()) {
            return null;
        }
        return select.get(0);
    }

    default UserEntity findUserByUserId(Integer userId) {
        List<UserEntity> select = selectList(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getId, userId));
        if (select.isEmpty()) {
            return null;
        }
        return select.get(0);
    }



    IPage<UserVO> listPage(Page<?> page);

    default IPage<UserVO> list(long pageNumber, long pageSize) {
        IPage<UserVO> userVOIPage = listPage(new Page<>(pageNumber, pageSize));
        return userVOIPage;
    }

}
